<?php

namespace app\models;

class Person extends \app\libs\orm\Model
{
    public $id;
    public $firstnames;
    public $lastname;
    public $maidenname;
    public $nickname;
    public $gender;
    public $photo;
    public $birthdate;
    public $deathdate;
    public $parents;
    public $unknown;
    public $user;

    public function relation()
    {
        return Relation::findOne(['person1' => $this->id]);
    }

    public function parents()
    {
        return Relation::find($this->parents);
    }

    public function firstname()
    {
        $stack = explode(' ', $this->firstnames);
        return $stack[0];
    }

    public function fullname()
    {
        return $this->firstname() . ' ' . $this->lastname;
    }

    public function birthdate()
    {
        $birthdate = '---';

        if($this->birthdate)
        {
            $date = new \DateTime($this->birthdate);
            $birthdate = $date->format('d M Y');
        }

        return $birthdate;
    }

    public function events()
    {
        return Event::find(['person' => $this->id]);
    }
}